// pages/addCommunity/addCommunity.js
var amapFile = require('../libs/amap-wx.130')
Page({
    /**
     * 页面的初始数据
     */
    data: {
        id:'',
        latitude: '',
        longitude: '',
        place: '',
        post: '',
        formData: {
            address: '',
            code: ''
        }
    },
    
    getverify() {
        wx.request({
          url: 'http://127.0.0.1:4523/m1/2213431-0-default/verify',
          method: 'POST',
          data: {
              post: this.data.post
          },
          success: (res) => {
            console.log(res);
        }
        })
    },

    addcommunity() {
        wx.request({
          url: 'http://127.0.0.1:4523/m1/2213431-0-default/addcommunity',
          method:'POST',
          data:{
              id: this.data.id,
              address:this.data.formData.address,
              code: this.data.formData.code
          },
          success: (res) => {
            console.log(res);
        }
        })
    },

    getUsercommunity(e) {
        this.setData({
            [`${e.currentTarget.dataset.gater}`]: e.detail.value
          })
          console.log(this.data.formData);
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let value1 = wx.getStorageSync('id')
        let value2 = wx.getStorageSync('post')
        this.setData({
            id: value1,
            post: value2
        })
        console.log(this.data.id);
        console.log(this.data.post);
        var that = this;
        var myAmapFun = new amapFile.AMapWX({key:'c60f86849fe6cd78a51af6774f57056c'});
        //获取自己所在地址的定位
        myAmapFun.getRegeo({
          success: function(data){
            //成功回调
            console.log(data)
            console.log(data[0]);
            console.log(data[0].name);
            console.log(data[0].desc);
            that.setData({
                latitude: data[0].latitude,
                longitude: data[0].longitude,
                place: data[0].name + data[0].desc
            })
          },
          fail: function(info){
            //失败回调
            console.log(info)
          }
        })
    
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
       
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})